2000W / 48V LLC Battery-Charger  V1.00
xmc_prng.c
Go to the documentation of this file.
1 
50 #include "xmc_prng.h"
51 
52 #if defined (PRNG)
53 
54 /*********************************************************************************************************************
55  * API IMPLEMENTATION
56  *********************************************************************************************************************/
57 
58 /*
59  * Initializes the PRNG peripheral with the settings in the
60  * initialization structure XMC_PRNG_INIT_t
61  */
62 XMC_PRNG_INIT_STATUS_t XMC_PRNG_Init(const XMC_PRNG_INIT_t *prng)
63 {
64  volatile uint16_t read_warm_up;
65  uint16_t reg_val, iter;
66  XMC_PRNG_INIT_STATUS_t status = XMC_PRNG_INITIALIZED;
67 
68  XMC_ASSERT("XMC_PRNG_Init:Null Pointer", (prng != (XMC_PRNG_INIT_t *)NULL));
69 
70  /* Configure block size for key loading mode */
71  XMC_PRNG_SetRandomDataBlockSize(XMC_PRNG_RDBS_WORD);
72 
73  /* Enable key loading mode */
74  XMC_PRNG_EnableKeyLoadingMode();
75 
76  /* Load key words (80 bits) and wait till RDV is set */
77  for (iter = (uint16_t)0UL; iter < (uint16_t)5UL; iter++)
78  {
79  XMC_PRNG_LoadKeyWords(prng->key_words[iter]);
80  while (PRNG_CHK_RDV_Msk != XMC_PRNG_CheckValidStatus());
81  }
82 
83  XMC_PRNG_EnableStreamingMode();
84 
85  /* Warm up phase: Read and discard 64 bits */
86  read_warm_up = PRNG->WORD;
87  read_warm_up = PRNG->WORD;
88  read_warm_up = PRNG->WORD;
89  reg_val = PRNG->WORD;
90  read_warm_up &= reg_val;
91 
92  /* Configure block size either byte (8 bit) or word (16 bit) */
93  XMC_PRNG_SetRandomDataBlockSize(prng->block_size);
94 
95  /*
96  * Checks for reset value for "random data block size". If reset,
97  * PRNG is not initialized
98  */
99  if ((uint16_t)XMC_PRNG_RDBS_RESET == (PRNG->CTRL & (uint16_t)PRNG_CTRL_RDBS_Msk))
100  {
101  status = XMC_PRNG_NOT_INITIALIZED;
102  }
103 
104  return status;
105 }
106 
107 #endif /* #if defined (PRNG) */
#define PRNG_CTRL_RDBS_Msk
Definition: XMC1400.h:2168
#define XMC_ASSERT(msg, exp)
Definition: xmc_common.h:132
#define PRNG_CHK_RDV_Msk
Definition: XMC1400.h:2164
#define PRNG
Definition: XMC1400.h:8819